<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class WechatWeb extends Controller {

    public function __construct($ControllerName, $Action, $QueryString) {
        parent::__construct($ControllerName, $Action, $QueryString);
        global $config;
        $this->loadModel('Db');
        $this->loadModel('WechatSdk');
    }

    public function home() {
        $openid = $this->getOpenId();

        if (!WechatSdk::checkOpenIdExist($openid, $this->Db)) {
            header('location:?/WechatWeb/register.php');
            exit(0);
        }

        $this->show();
    }

    /**
     * 成为微代理引导页面
     */
    public function proxy() {
        $openid = $this->getOpenId();
        $settings = $this->getShopSettings();

        $this->Smarty->assign('settings', $settings);
        $this->show();
    }

    /**
     * 
     */
    public function companyReg() {
        $openid = $this->getOpenId();
        if (!$this->isCompany($openid)) {
            $this->show();
        } else {
            header('Location:' . $this->root . '?/Uc/home/');
        }
    }

    /**
     * 判断是否微代理
     */
    private function isCompany($openid) {
        return $this->Db->query("SELECT `uid` FROM `companys` WHERE `uid` = '$openid';");
    }

    /**
     * 关注欢迎页
     */
    public function welcome() {
        $this->show();
    }
    
    public function companyComs(){
        $this->show();
    }

}
